<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>component-4</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>component-4</h1>
    <hr>
    <div id="app">
        <component v-bind:is="who"></component>
        <button @click="changeComponent">changeComponent</button>
    </div>
    <script type="text/javascript">
    var componentA={
        template:`<div style="color:red">i'm componentA.</div>`
    }
    var componentB={
        template:`<div style="color:green">i'm componentB.</div>`
    }
    var componentC={
        template:`<div style="color:pink">i'm componentC.</div>`
    }
        var app=new Vue({
            el:'#app',
            data:{
                who:'componentA'
            },
            components:{
            "componentA":componentA,
            "componentB":componentB,
            "componentC":componentC
            },
            methods:{
                changeComponent:function(){
                    if(this.who=="componentA"){
                        this.who="componentB"
                    }
                    else if(this.who=="componentB"){
                        this.who="componentC"
                    }
                    else{
                        this.who="componentA"
                    }
                }
            }
        }) 
    </script>
</body>
</html>